package net.fdukedom.epicurus.plugin;

import java.util.Map;
import java.util.Set;

/**
 * Describes interface of collection loader, the class that parses one elemnt
 * of collection from one node in xml.
 *
 * @author Dmitry Y. Kochelaev
 */
public abstract class CollectionLoader<T, S> {
    /**
     * Item for which the collection is loaded.
     */
    protected T item;

    /**
     * Creates instance out of item.
     * @param item
     */
    public CollectionLoader(T item) {
        this.item = item;
    }

    /**
     * Parses one element of collection from given map of attributes.
     *
     * @param attributes attributes of element
     *
     * @return element of collection
     */
    public abstract S parseAttributes(Map<String, String> attributes);


    /**
     * Returns old collection. The collection that was stored in database.
     *
     * @return old collection
     */
    public abstract Set<S> getLoadedCollection();

    /**
     * Disposes element. This method is to remove element from all collections
     * and remove links from element to its parents.
     *
     * @param element element to be disposed
     */
    public abstract void disposeElement(S element);

    /**
     * Adds element. This method is to add element to all collections and
     * set its parents.
     *
     * @param element element to be added
     */
    public abstract void addElement(S element);
}
